package com.example.match.service;

import com.example.match.model.domain.User;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

/**
 * @author 雨后天晴
 * @version 1.0
 * @since 2024/9/25 18:33
 */
@SpringBootTest
public class RedisTest {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;


    @Test
    public void test() {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        // 增
        valueOperations.set("nameString", "张三");
        valueOperations.set("nameInt", 1);
        valueOperations.set("nameDouble", 2.0);
        User user = new User();
        user.setId(1L);
        user.setUsername("张三");
        user.setUserAccount("123456");
        valueOperations.set("user", user);
        // 查
        Object nameString = valueOperations.get("nameString");
        Assertions.assertTrue("张三".equals(nameString));
        Object nameInt = valueOperations.get("nameInt");
        Assertions.assertTrue(1 == (int) nameInt);
        Object nameDouble = valueOperations.get("nameDouble");
        Assertions.assertTrue(2.0 == (double) nameDouble);
        System.out.println(valueOperations.get("user"));
    }
    @Test
    public void test2() {
        redisTemplate.delete("nameString");
    }
}
